/*
 *失效优惠券列表
 */
require(['jquery','../modules/pageSize','../modules/popup', 'jqScroller'],function($,pageSetSize,popup){
	//设置html根目录字体大小
    setRootFontSize(pageSetSize);
    var curPagePos = 1;		 
	$(".progress-loader a").on("click", function(e){
        e.preventDefault();
		if(jqScroller.isBlock()) return;
		jqScroller.block();
        jqScroller.render(curPagePos);
    });	
	/*请求优惠券列表*/
	jqScroller.render = function(cpage){
        popup.loadPopup("正在加载中...");
        $.ajax({
            type: "GET",
            url: "/Home/Member/apimemberCouponFail"+getFixedExtraUrl(),
            data: { "page" : cpage},
            dataType: "json",
            success: function (rs) {
                popup.removeLoad();
				if(rs && rs.data != null)  {
                    renderCouponList(rs.data);
					curPagePos++;
                    jqScroller.curPage++;
                    jqScroller.unblock();
                    $(".progress-loader").css("display", "");
                }else{
					jqScroller.done();
                    $(".progress-loader").css("display", "none");
                    if(curPagePos == 1){
                        $("#yc_sx_empty").css("display", "block");    
                    }else{                        
                        popup.alertPopup("没有更多数据！");
                    }                    
                }              
            },
            error: function () {
                popup.removeLoad();
                popup.alertPopup('服务器异常，请稍后重试！');
                jqScroller.unblock();
            }
        });
    };
    jqScroller.run();
    jqScroller.render(1);
	/*渲染优惠券列表*/
	function renderCouponList(list){
		var output = "";
		var c;
		for(var k in list){
			c = list[k];
			output += '<div class="coupon-item forbiden">';
			output += '<h1>'+c["name"]+'</h1>';
			output += '<h5>'+c["description"]+'</h5>';
			output += '<h5 style="width:100%">有效期:'+c["start_time"]+'-'+c["end_time"]+'</h5>';
			output += '<span  class="coupon-shop" style="color:#c7cac9"><i><img src="/Public/Home/images/shop-icon-coupan.png"></i>'+c["local_name"]+'</span>';
			output += '</div>';
		}
		if(curPagePos % 10 == 0){
			$("#ajax-couponlist").html(output);	
		}else{
			$("#ajax-couponlist").append(output);
		}
	}
	$('.delete-fail-coupon a').on('click',function(){
        $.ajax({
            url:'/Home/Member/deleteCouponFail'+getFixedExtraUrl(),
            type:'post',
            dataType:'json',
            success:function(rs){
				popup.alertPopup(rs.msg);
                if(rs.status == 1){
                    $('.coupon-list').children().remove();
                    $('.coupon-des').remove();
                    $('#yc_sx_empty').css('display','block');
                }
            },
            error:function(){
                popup.alertPopup('服务器异常，请稍后重试！');
            }
        });
    });
});